package org.adorsys.aderp.orga.repository;

import java.util.List;

import org.adorsys.aderp.orga.domain.OrgaPerson;
import org.adorsys.aderp.orga.domain.OrgaResource;
import org.adorsys.aderp.orga.domain.ResResRelation;
import org.adorsys.aderp.orga.domain.ResourceRelation;
import org.adorsys.aderp.orga.domain.ResourceRelationRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.roo.addon.layers.repository.jpa.RooJpaRepository;

@RooJpaRepository(domainType = ResourceRelation.class)
public interface ResourceRelationRepository {
	
	List<ResourceRelation> findByTargetResource(OrgaResource orgaResource);
	List<ResourceRelation> findByPerson(OrgaPerson person);
	
	/**
	 * targetResource is not null.
	 * 
	 * @param orgaResource
	 * @param pageable
	 * @return
	 */
	Page<ResourceRelation> findByTargetResource( OrgaResource targetResource,Pageable pageable);
    Page<ResourceRelation> findByTargetResourceAndPerson(OrgaResource targetResource,OrgaPerson person,Pageable pageable);
    Page<ResourceRelation> findByTargetResourceAndPersonAndRelationRole(OrgaResource targetResource,OrgaPerson person,ResourceRelationRole relationRole,Pageable pageable);
	Page<ResourceRelation> findByTargetResourceAndRelationRole( OrgaResource targetResource,ResourceRelationRole relationRole,Pageable pageable);

    
    /**
	 * targetResource is null and person is not null
	 * @param person
	 * @param pageable
	 * @return
	 */
    Page<ResourceRelation> findByPerson(OrgaPerson person,Pageable pageable);
    Page<ResourceRelation> findByPersonAndRelationRole(OrgaPerson person,ResourceRelationRole relationRole,Pageable pageable);

    /**
   	 * targetResource is null and person is  null
   	 * @param relationRole
   	 * @param pageable
   	 * @return
   	 */
	
	Page<ResourceRelation> findByRelationRole(ResourceRelationRole relationRole, Pageable pageable);

}
